package cn.admin.configcenter.registry.common.util;

import cn.admin.configcenter.registry.common.constants.WarningCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class ConfigWarnings {
    private static final Logger log = LoggerFactory.getLogger("MonitorLog");
    private static final String dataEmptyLogPrefix = "PushEmptyData:";
    private static final Map<WarningCode, Long> history = new HashMap<>();

    public ConfigWarnings() {
    }

    public static synchronized void warning(WarningCode wc, String msg) {
        Long lastWarnTime = history.get(wc);
        long now = System.currentTimeMillis();
        if (null == lastWarnTime || now - lastWarnTime > TimeUnit.MINUTES.toMillis(5L)) {
            log.info("PushEmptyData:" + wc.getCode() + " " + msg);
            history.put(wc, now);
        }

    }
}